package org.absolutezero.server;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.servlet.http.HttpServlet;

import org.absolutezero.model.EMF;
import org.absolutezero.model.Generator;
import org.absolutezero.model.Product;



public class OnStartupServlet extends HttpServlet{

	
	public void init(){
		Generator g = new Generator();
		
		List<Product> products = g.generateProducts(100);
		EntityManager em = EMF.get().createEntityManager();
		try{
			EntityTransaction tx = em.getTransaction();
			tx.begin();
			for(Product p : products){
				em.persist(p);
			}
			tx.commit();
		}
		finally{
			em.close();
		}
	}
}
